<?php
namespace App\Controllers;
use \interop\Container\ContainerInterface as ContainerInterface;
use App\Models\UserModel;
use App\Models\OperaModel;
use pdo;
class FlowerController extends BaseController{
	public function getflower($request,$respone,$args){
		$user=new UserModel();
		$oper=new OperaModel();
		$flowername=$request->getParam('flowername');
		if($flowername==""){
		   if($user->getflower()){
		    $data=json_encode($user->getflower());
		   }
		}else{
			$data=json_encode($oper->searchflower($flowername));
		}
		    return $data;
     }
     public function flowerstock($request,$respone,$args){
     	$user=new UserModel();
		$oper=new OperaModel();
		$flowername=$request->getParam('flowername');
		if($flowername==""){
		   if($user->flowerstock()){
		    $data=json_encode($user->flowerstock());
		   }
		}else{
			$data=json_encode($oper->searchstock($flowername));
		}
		    return $data;
     }
     public function flowermsg($request,$respone,$args){
     	$oper=new OperaModel();
     	$id=$request->getParam('id');
     	if($oper->flowermsg($id)){
     		$data=json_encode($oper->flowermsg($id));
     	}else{
     		$data='a';
     	}
     	return $data;
     }
     public function stockdelect($request,$respone,$args){
     	$oper=new OperaModel();
     	$ids=$request->getParam('id');
     	if(is_array($ids)){
     		$id= implode(",",$ids);
     		if($oper->delstocks($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	else{
     		$id=$ids;
     		if($oper->delstock($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	return $respone->withJSON($data);
     }
     public function stockmsg($request,$respone,$args){
     	$oper=new OperaModel();
     	$id=$request->getParam('id');
     	if($oper->stockmsg($id)){
     		$ret=json_encode($oper->stockmsg($id));
     		$data=array('message'=>"$ret",'code'=>0);
     	}else{
     		$data=array('message'=>'用户操作失败','code'=>101);
     		
     	}
     	return $respone->withJSON($data);;
     }
     public function stockedit($request,$respone,$args){
     	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	$flowername=$request->getParam('flowername');
    	$flowerprice=$request->getParam('flowerprice');
    	$flowersize=$request->getParam('flowersize');
    	$flowerproduct=$request->getParam('flowerproduct');
    	$flowertype=$request->getParam('flowertype');
    	$flowerinprice=$request->getParam('flowerinprice');
    	$flowerupstock=$request->getParam('flowerupstock');
    	$flowerdownstock=$request->getParam('flowerdownstock');
    	$supplier=$request->getParam('supplier');
    	$count=$request->getParam('count');
    	$ret=json_encode($oper->stockedit($id,$flowername,$flowerprice,$flowersize,$flowerproduct,$flowertype,$flowerinprice,$flowerupstock,$flowerdownstock,$supplier,$count));
		if($ret){
		  $data=array('massage'=>"编辑成功",'code'=>"$ret");
		}else{
	      $data=array('massage'=>"编辑失败",'code'=>101);
        }
        return $respone->withJson($data);
     }
     public function stockadd($request,$respone,$args){
     	$oper=new OperaModel();
    	$flowername=$request->getParam('flowername');
    	$flowerprice=$request->getParam('flowerprice');
    	$flowersize=$request->getParam('flowersize');
    	$flowerproduct=$request->getParam('flowerproduct');
    	$flowertype=$request->getParam('flowertype');
    	$flowerinprice=$request->getParam('flowerinprice');
    	$flowerupstock=$request->getParam('flowerupstock');
    	$flowerdownstock=$request->getParam('flowerdownstock');
    	$supplier=$request->getParam('supplier');
    	$count=$request->getParam('count');
    	$ret=json_encode($oper->stockadd($flowername,$flowerprice,$flowersize,$flowerproduct,$flowertype,$flowerinprice,$flowerupstock,$flowerdownstock,$supplier,$count));
		if($ret){
		  $data=array('massage'=>"添加成功",'code'=>"$ret");
		}else{
	      $data=array('massage'=>"添加失败",'code'=>101);
        }
        return $respone->withJson($data);
     }
     public function uploadimg($request,$respone,$args){
     	$a = '{"code": 0,"msg": "","data": {"src": ""}}';
        $a = json_encode($a);
        return "$a";
     }
     public function showedit($request,$respone,$args){
     	$oper=new OperaModel();
     	$id=$request->getParam('id');
     	$flowername=$request->getParam('flowername');
     	$flowerprice=$request->getParam('flowerprice');
     	$love=$request->getParam('love');
     	$sold=$request->getParam('sold');
     	$img=$request->getParam('img');
     	$ret=json_encode($oper->showedit($id,$flowername,$flowerprice,$love,$sold,$img));
     	if($ret){
		  $data=array('massage'=>"编辑成功",'code'=>"$ret");
     	}else{
	      $data=array('massage'=>"编辑失败",'code'=>101);	
     	}
        return $respone->withJson($data);
     }
}
?>